home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / Install / program files / Borland / BDS / 3.0 / Demos / Delphi.Net / CLR / Threading / timerthread.dpr < prev   
Encoding:
Text File  |  2004-10-22  |  854 b   |  37 lines

  1. program timerthread.dpr;
  2. {$APPTYPE CONSOLE}
  3.  
  4. //
  5. // This example demonstrates how to use the .NET timer to perform an 
  6. // operation on another thread.
  7. //
  8. // Written by: Rick Ross (http://www.rick-ross.com/)
  9. //
  10.  
  11. uses System.Threading;
  12.  
  13. type
  14.   TMyTimerClass = class
  15.   public
  16.     procedure Alarm(state : System.Object);
  17.   end;
  18.  
  19. procedure TMyTimerClass.Alarm(state : System.Object);
  20. begin
  21.   writeln(AppDomain.GetCurrentThreadID(),' Bzzzz. Time to wake up!');
  22.   if assigned(state) then
  23.     writeln('You passed me: ', state.ToString());
  24. end;
  25.  
  26. var
  27.   tc : TMyTimerclass;
  28.   t  : Timer;
  29.  
  30. begin
  31.   tc := TMyTimerClass.Create;
  32.   t  := Timer.Create( @tc.Alarm, nil, 1000 , 0);
  33.   writeln(AppDomain.GetCurrentThreadID(),' Waiting for the alarm... zzzzz');
  34.   Thread.Sleep(2000);
  35.   writeln(AppDomain.GetCurrentThreadID(),' Done!');
  36. end.
  37.